﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;

namespace DevToolsRepo
{
	public class ToolInfo
	{
		public string Name { get; set; }
		public string URL { get; set; }
		public string Description { get; set; }
		public List<VersionInfo> Versions { get; set; }
		public List<TagInfo> Tags { get; set; }

		[XmlIgnore]
		public string TagsSeperated
		{
			get
			{
				return string.Join(", ", Tags.Select(o => o.Title).ToArray());
			}
			set
			{
				var tags = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				var tagInfos = new List<TagInfo>();
				foreach (var tag in tags)
				{
					var tagInfo = ToolRepository.Instance.Tags.Where(o => o.Title == tag).FirstOrDefault();
					if (tagInfo == null)
					{
						tagInfo = new TagInfo { Title = tag.Trim() };
						ToolRepository.Instance.Tags.Add(tagInfo);
					}

					tagInfos.Add(tagInfo);
				}

				Tags = tagInfos;
			}
		}

		public ToolInfo()
		{
			Versions = new List<VersionInfo>();
			Tags = new List<TagInfo>();
		}

		public override string ToString()
		{
			return Name + ", Versions: " + Versions.Count + ", Tags: " + Tags.Count;
		}
	}
}
